
package com.wiesloch.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wiesloch.mapper.DistributorMapper;
import com.wiesloch.po.Distributor;
import com.wiesloch.po.Page;
import com.wiesloch.po.PageBean;

/**
 * <p>ClassName:DistributorService</p>
 * <p>Description:</p>
 * <p> E-mail:jintao_iknow@163.com </p>
 * Date:     2016年5月10日 下午6:16:04 <br/>
 * @author   tao95
 * @version  1.0
 * @since    JDK 1.7
 *
 */
@Service("distributorService")
public class DistributorService {
	
	@Autowired
	private DistributorMapper distributorMapper;
	
	
	/**
	 * @description 登录时通过账户查询分销商
	 * @param distributor
	 * @return
	 * @throws Exception
	 */
	public Distributor selectDistributor(Distributor distributor) throws Exception{
		return distributorMapper.selectDistributor(distributor);
	}
	
	/**
	 * @description 通过id查询分销商
	 * @param distributor
	 * @return
	 * @throws Exception
	 */
	public Distributor selectDistributorById(Integer id) throws Exception{
		return distributorMapper.selectDistributorById(id);
	}
	
	/**
	 * @param pageSize 
	 * @param pageNum 
	 * @description 通过pid查询一级分销商
	 * @param distributor
	 * @return
	 * @throws Exception
	 */
	public PageBean selectChildrenListBypid(Page page) throws Exception{
		Integer recordCount = distributorMapper.selectCountChildren(page.getPid());
		List<Distributor> recordList = distributorMapper.selectChildrenListBypid(page);
		return new PageBean(page.getPageNum(), page.getPageSize(), recordCount,
				recordList);
	}
	/**
	 * @description 通过id设置分销商的状态为已删除
	 * @param distributor
	 * @return
	 * @throws Exception
	 */
	public void deleteById(Integer id) throws Exception{
		distributorMapper.deleteById(id);
	}
	
	/**
	 * @description 添加新的分销商，返回分销商的id
	 * @param distributor
	 * @return
	 * @throws Exception
	 */
	public Integer addDistributor(Distributor distributor) throws Exception{
		return distributorMapper.addDistributor(distributor);
	}
	
	/**
	 * @description 查询所有的省市分销商
	 * @param distributor
	 * @return
	 * @throws Exception
	 */
	public List<Distributor> slectDistributorProvince() throws Exception{
		return distributorMapper.slectDistributorProvince();
	}
	
	/**
	 * @description 更新分销商的信息
	 * @param distributor
	 * @return
	 * @throws Exception
	 */
	public void updateDistributorById(Distributor distributor) throws Exception{
		distributorMapper.updateDistributorById(distributor);
		
	}
}
